import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ToastController } from '@ionic/angular';
import { HttpService } from 'src/app/service/http.service';

@Component({
  selector: 'app-contacts-apply',
  templateUrl: './contacts-apply.component.html',
  styleUrls: ['./contacts-apply.component.scss'],
})
export class ContactsApplyComponent implements OnInit {

  contact: any = {};

  constructor(private activatedRoute: ActivatedRoute, public toastController: ToastController, private httpService: HttpService) { }

  ngOnInit() {
    //获取参数值
    this.contact.id = this.activatedRoute.snapshot.params['userid'];
    console.log(this.contact)
    this.toastController.create({
      message: JSON.stringify(this.contact),
      duration: 2000
    }).then(value => {
      value.present()
    })
  }

  async addContact() {
    const {data} = await this.httpService.addContact(this.contact)

    const toast = await this.toastController.create({
      message: 'Your settings have been saved.',
      duration: 2000
    });
    await toast.present();
  }
}
